Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
wasm-feature-detect
Advanced tools
A small library to detect which features of WebAssembly are supported in your current browser.
The wasm-feature-detect npm package is designed to help developers detect the availability of various WebAssembly (Wasm) features in the user's environment. This can be particularly useful for ensuring compatibility and optimizing performance by leveraging specific Wasm capabilities when they are available.
Detect SIMD Support
This feature allows you to detect if SIMD (Single Instruction, Multiple Data) is supported in the user's environment. SIMD can significantly improve performance for certain types of computations.
const wasmFeatureDetect = require('wasm-feature-detect');
wasmFeatureDetect.simd().then(supported => {
if (supported) {
console.log('SIMD is supported');
} else {
console.log('SIMD is not supported');
}
});
Detect Bulk Memory Operations Support
This feature checks if bulk memory operations are supported. Bulk memory operations can be used to efficiently manage memory in WebAssembly.
const wasmFeatureDetect = require('wasm-feature-detect');
wasmFeatureDetect.bulkMemory().then(supported => {
if (supported) {
console.log('Bulk Memory Operations are supported');
} else {
console.log('Bulk Memory Operations are not supported');
}
});
Detect Multi-Value Support
This feature detects if the multi-value extension is supported. Multi-value allows WebAssembly functions to return multiple values, which can simplify certain programming patterns.
const wasmFeatureDetect = require('wasm-feature-detect');
wasmFeatureDetect.multiValue().then(supported => {
if (supported) {
console.log('Multi-Value is supported');
} else {
console.log('Multi-Value is not supported');
}
});
The wasm-check package is another alternative for detecting WebAssembly features. It provides a simple API to check for the availability of specific Wasm capabilities. While it covers many of the same features as wasm-feature-detect, it may have a different set of supported features and a different API design.
A small library to detect which features of WebAssembly are supported.
npm install -g wasm-feature-detect
<script type="module">
import { simd } from "wasm-feature-detect";
if (await simd()) {
/* SIMD support */
} else {
/* No SIMD support */
}
</script>
<script type="module">
import { simd } from "https://unpkg.com/wasm-feature-detect?module";
// ...
</script>
If required, there’s also a UMD version
<script src="https://unpkg.com/wasm-feature-detect/dist/umd/index.js"></script>
<script>
if (await wasmFeatureDetect.simd()) {
// ...
}
</script>
All detectors return a Promise<bool>
.
Function | Proposal |
---|---|
bigInt() | BigInt integration |
bulkMemory() | Bulk memory operations |
exceptions() | Legacy Exception Handling |
exceptionsFinal() | Exception Handling with exnref |
extendedConst() | Extented Const Expressesions |
gc() | Garbage Collection |
jsStringBuiltins() | JS String Builtins Proposal for WebAssembly |
jspi() | JavaScript Promise Integration |
memory64() | Memory64 |
multiMemory() | Multiple Memories |
multiValue() | Multi-value |
mutableGlobals() | Importable/Exportable mutable globals |
referenceTypes() | Reference Types |
relaxedSimd() | Relaxed SIMD |
saturatedFloatToInt() | Non-trapping float-to-int conversions |
signExtensions() | Sign-extension operators |
simd() | Fixed-Width SIMD |
streamingCompilation() | Streaming Compilation |
tailCall() | Tail call |
threads() | Threads |
typeReflection() | Type Reflection |
typedFunctionReferences() | Typed function references |
The technical reason is that some tests might have to be augmented to be asynchronous in the future. For example, Firefox is planning to make a change that would require a postMessage
call to detect SABs, which are required for threads.
The other reason is that you should be using WebAssembly.compile
, WebAssembly.instantiate
, or their streaming versions WebAssembly.compileStreaming
and WebAssembly.instantiateStreaming
, which are all asynchronous. You should already be prepared for asynchronous code when using WebAssembly!
If you want to contribute a new feature test, all you need to do is create a new folder in src/detectors
and it will be automatically picked up. The folder may contain a module.wat
file, which will be compiled using wabt.js
.
;; Name: <Name of the feature for the README>
;; Proposal: <Link to the proposal’s explainer/repo>
;; Features: <Space-separated list of WasmFeatures from wabt.js>
(module
;; More WAT code here
)
The folder can also contain an optional index.js
file, whose default export must be an async function. This function can do additional testing in JavaScript and must return a boolean. See the “threads” detector as an example.
It must contain at least one of module.wat
or index.js
.
License Apache-2.0
FAQs
A small library to detect which features of WebAssembly are supported in your current browser.
We found that wasm-feature-detect demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.